﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace teacherplanner
{
    public partial class DefineClasses : Form
    {
        public DefineClasses()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "")
            {
                listBox1.Items.Add(textBox1.Text);
                textBox1.Text = "";
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            listBox1.Items.Remove(listBox1.SelectedItem);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            int myArraySize = listBox1.Items.Count;
            if (myArraySize < 1)
            {
                MessageBox.Show("You must add at least one class.","Input Error",MessageBoxButtons.OK);
                return;
            }
            DataBase.Edit.CreateTable("CREATE TABLE Classes (ClassID INT IDENTITY(1,1) NOT NULL, ClassName VARCHAR(25))");
            String[] InsertArray = new String[myArraySize];
            for (int i = 0; i < myArraySize; i++)
            {
                int myInt = i + 1;
                InsertArray[i] = @"INSERT INTO Classes VALUES ('" + myInt + "','" + listBox1.Items[i] + "')";
            }
 
            DataBase.Edit.ApplySQLArray(InsertArray);
            DefineClasses.ActiveForm.Hide();
            teacherplanner.SetDatesForm myForm = new teacherplanner.SetDatesForm();
            myForm.Show();
        }
    }
}
